﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Portal.Xml.Utility;

namespace Portal.Cms.Model
{
    public class GroupDataFolderCls
    {
        public string GroupDataFolderId;
        public string GroupDataId;
        public string FolderName;
        public string Description;
        public string ParentGroupDataFolderId;
        public int SortIndex;
    }

    public class GroupDataFolderParser
    {
        public static GroupDataFolderCls CreateInstance()
        {
            //tao 1 class trang....
            GroupDataFolderCls oGroupDataFolderCls = new GroupDataFolderCls();
            return oGroupDataFolderCls;
        }

        public static GroupDataFolderCls ParseFromXml(string XmlData)
        {
            DataSet ds = XmlUtility.GetDataSetFromXml(XmlData);
            GroupDataFolderCls oGroupDataFolderCls = ParseFromDataRow(ds.Tables[0].Rows[0]);
            return oGroupDataFolderCls;
        }


        public static GroupDataFolderCls ParseFromDataRow(DataRow dr)
        {
            GroupDataFolderCls oGroupDataFolderCls = new GroupDataFolderCls();
            oGroupDataFolderCls.GroupDataFolderId = XmlUtility.GetString(dr, "GroupDataFolderId", true);
            oGroupDataFolderCls.GroupDataId = XmlUtility.GetString(dr, "GroupDataId", true);
            oGroupDataFolderCls.FolderName = XmlUtility.GetString(dr, "FolderName", true);
            oGroupDataFolderCls.Description = XmlUtility.GetString(dr, "Description", true);
            oGroupDataFolderCls.Description = XmlUtility.GetString(dr, "Description", true);
            oGroupDataFolderCls.ParentGroupDataFolderId = XmlUtility.GetString(dr, "ParentGroupDataFolderId", true);
            oGroupDataFolderCls.SortIndex = XmlUtility.GetInt(dr, "SortIndex", true);

            return oGroupDataFolderCls;
        }

        public static GroupDataFolderCls[] ParseFromDataTable(DataTable dtTable)
        {
            GroupDataFolderCls[] GroupDataFolders = new GroupDataFolderCls[dtTable.Rows.Count];
            for (int iIndex = 0; iIndex < dtTable.Rows.Count; iIndex++)
            {
                GroupDataFolders[iIndex] = ParseFromDataRow(dtTable.Rows[iIndex]);
            }

            return GroupDataFolders;
        }

        public static GroupDataFolderCls[] ParseMultiRecordFromXml(string XmlData)
        {
            DataSet ds = XmlUtility.GetDataSetFromXml(XmlData);
            if (ds.Tables.Count == 0)
            {
                return new GroupDataFolderCls[0];
            }
            GroupDataFolderCls[] GroupDataFolders = new GroupDataFolderCls[ds.Tables[0].Rows.Count];
            for (int iIndex = 0; iIndex < ds.Tables[0].Rows.Count; iIndex++)
            {
                GroupDataFolders[iIndex] = ParseFromDataRow(ds.Tables[0].Rows[iIndex]);
            }
            return GroupDataFolders;
        }
    }
}

